import {
	reactive,
	ref,
	toRefs,
	getCurrentInstance,
	watch,
	computed
} from "vue"
import {
	onReady,
	onLoad,
	onShow,
	onReachBottom,
	onPullDownRefresh
} from '@dcloudio/uni-app'

import store from '@/store/index.js'; //需要引入store

export default function() {
	const {
		proxy
	} = getCurrentInstance();
	// 确认发货
	const confirmOrder = (sid,data,callback) =>{
		updateStatusOrder(sid,2,data,callback)
	}
	// 取消订单
	const cancelOrder = (sid,data,callback) =>{
		// console.log(sid);
		// console.log(data);
		updateStatusOrder(sid,3,data,callback)
	}
	// 修改订单状态
	const updateStatusOrder = (sid,status,data,callback) =>{
		let _data = {
			sid:sid,
			status:status,
			...data
		}
		proxy.$u.api.updateStatusOrder(_data).then(res => {
			let {
				code,
				msg,
				data
			} = res;
			if (code == 200) {
				// uni.$emit('order_update')
				uni.$u.toast(msg || '成功');
				if(typeof callback == 'function'){
					callback();
				}
			} else {
				uni.$u.toast(msg || '错误');
			}
		}).catch(()=>{
			
		})
	}
	return {
		confirmOrder,
		cancelOrder
	}
}